﻿using System;
using System.Collections.Generic;
using System.Text;

namespace MinecraftBackupAssistant
{
	public enum Direction
	{
		North, East, South, West
	}

	public enum CaveRenderingState
	{
		Disabled, Caves, Blended
	}

    [Serializable]
    public class MapperSettings
    {
		public Direction TopLeftDirection { get; set; }
		public CaveRenderingState CaveRenderingState { get; set; }
        public bool Night { get; set; }
		public bool RenderSkylight { get; set; }

		public MapperSettings() : this(Direction.East, CaveRenderingState.Disabled, false, false) { }
        public MapperSettings(Direction topLeftDirection, CaveRenderingState caveRenderingState, bool night, bool renderSkylight)
        {
			TopLeftDirection = topLeftDirection;
			CaveRenderingState = caveRenderingState;
            Night = night;
			RenderSkylight = renderSkylight;
        }

        public static Direction DirectionEnumFromString(string imageType)
        {
            try
            {
                return (Direction)Enum.Parse(typeof(Direction), imageType, true);
            }
            catch (Exception) //invalid name
            {
                return Direction.East;
            }
        }

		public static CaveRenderingState TimeOfDayEnumFromString(string timeOfDay)
        {
            try
            {
				return (CaveRenderingState)Enum.Parse(typeof(CaveRenderingState), timeOfDay, true);
            }
            catch (Exception) //invalid name
            {
				return CaveRenderingState.Disabled;
            }
        }

        public string GenerateMapperParameterString(string savePath)
        {
            string outputString;

            savePath = String.Format("\"{0}\"", savePath);

            string direction = "-" + this.TopLeftDirection.ToString().ToLower();

			string renderCaves;
			if (CaveRenderingState == CaveRenderingState.Caves)
				renderCaves = "-cave";
			else if (CaveRenderingState == CaveRenderingState.Blended)
				renderCaves = "-blendcave";
			else
				renderCaves = String.Empty;


			string night = this.Night ? "-night" : String.Empty;
			string skylight = this.RenderSkylight ? "-skylight" : String.Empty;

            outputString = String.Format("{0} {1} {2} {3} {4}", renderCaves, direction, night, skylight, savePath);
            return outputString;
        }
    }
}
